﻿using System;
using System.Windows.Forms;
using Presentation;
using Infrastructure;

namespace WinClient
{
    public partial class View : Form, IView
    {
        private readonly Presenter presenter;
        private ILogger logger;
        private HtmlLogger htmlLogger;
        private TxtLogger txtLogger;

        public View()
        {
            InitializeComponent();
            
            txtLogger = new TxtLogger();
            htmlLogger = new HtmlLogger();
            logger = txtLogger;
            presenter = new Presenter(this);
        }

        public string array
        {
            get
            {
                return textBoxArray.Text;
            }
            set
            {
                textBoxArray.Text = value;
            }
        }
        public string elementToFind
        {
            get
            {
                return textBoxElemntToFind.Text;
            }
            set
            {
                textBoxElemntToFind.Text = value;
            }
        }
        public string sortedArray
        {
            get
            {
                return textBoxSortedArray.Text;
            }
            set
            {
                textBoxSortedArray.Text = value;
            }
        }
        public string position
        {
            get
            {
                return textBoxPosition.Text;
            }
            set
            {
                textBoxPosition.Text = value;
            }
        }
        public string errorMessage
        {
            get 
            { 
                return ErrorLabel.Text; 
            }
            set
            {
                ErrorLabel.Text = value;
            }
        }

        private void buttonSearch_Click(object sender, EventArgs e)
        {
            presenter.Search();

            presenter.WriteToLog(txtLogger);
            presenter.WriteToLog(htmlLogger);
        }

        private void buttonShowLog_Click(object sender, EventArgs e)
        {
            System.Diagnostics.Process.Start(logger.fileName);
        }

        private void radioButtonTxtLog_CheckedChanged(object sender, EventArgs e)
        {
            logger = txtLogger;
        }

        private void radioButtonHtmlLog_CheckedChanged(object sender, EventArgs e)
        {
            logger = htmlLogger;
        }
    }
}
